package com.google.code.io;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class OUT {
	private static String DEFAULT_ENCODING = "UTF-8";

	public static void setDefaultEncoding(String encoding)
			throws UnsupportedEncodingException {
		new PrintStream(System.out, true, encoding);
		DEFAULT_ENCODING = encoding;
	}

	public static void print(Object obj) {
		print(obj, DEFAULT_ENCODING);
	}

	public static void println(Object obj) {
		println(obj, DEFAULT_ENCODING);
	}

	public static void print(Object obj, String encoding) {
		try {
			PrintStream ps = new PrintStream(System.out, true, encoding);
			ps.print(obj);
		} catch (UnsupportedEncodingException e) {
			System.out.print(encoding + " not supported, using stdout.");
			System.out.print(obj);
		}
	}

	public static void println(Object obj, String encoding) {
		try {
			PrintStream ps = new PrintStream(System.out, true, encoding);
			ps.println(obj);
		} catch (UnsupportedEncodingException e) {
			System.out.print(encoding + " not supported, using stdout.");
			System.out.println(obj);
		}
	}
}
